from django.shortcuts import render
from Register.models import *
from django.http import *
from django.http import HttpResponseRedirect
from django.shortcuts import redirect


# Create your views here.

# 设置登录视图函数
def login(request):
    # 提交表单之后应该是一个post请求,第一次请求登录界面是GEt请求,根据不同的请求方式来判断用户的行为
    if request.method == "GET":
        return render(request, "User.html")
    if request.method == "POST":
        post = request.POST
        username = post.get("username")
        s = Student.objects.get(name=username)
        if s:
            password = post.get("password")
            if password == s.password:
                return JsonResponse({"status_num": 0})
            else:
                return JsonResponse({
                    "status_num": 1
                })
        else:
            return JsonResponse({
                "status_num": 1
            })
